package com.chushouya.controller.product.admin;

import com.chushouya.common.constant.ServiceType;
import com.chushouya.product.dto.admin.attribute.*;
import com.general.framework.core.enums.BusinessType;
import com.general.framework.core.schema.PageResult;
import com.general.framework.core.schema.Response;
import com.general.framework.web.annotations.Log;
import com.general.framework.web.annotations.RepeatSubmit;
import com.chushouya.product.service.admin.AttributeItemValueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = ServiceType.PLATFORM + "属性项目值管理")
@RestController
@RequestMapping(ServiceType.PLATFORM + "/attributeItemValue")
public class AttributeItemValueController {

    @Resource
    private AttributeItemValueService attributeItemValueService;

    @ApiOperation("获取属性项目值分页列表")
    @GetMapping("/page")
    public Response<PageResult<AttributeItemValueListDTO>> page(AttributeItemValueQuery query) {
        return Response.success(attributeItemValueService.selectAttributeItemValuePageResult(query));
    }

    @ApiOperation("获取属性项目值列表")
    @GetMapping("/list")
    public Response<List<AttributeItemValueListDTO>> list(AttributeItemValueQuery query) {
        return Response.success(attributeItemValueService.selectAttributeItemValueList(query));
    }

    @ApiOperation("根据ID获取属性项目值详细信息")
    @GetMapping("/detail")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "valueId", value = "属性项目值ID", required = true),
    })
    public Response<AttributeItemValueDetailDTO> getDetail(Long valueId) {
        return Response.success(attributeItemValueService.getAttributeItemValueDetail(valueId));
    }

    @ApiOperation("新增属性项目值")
    @Log(businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @RepeatSubmit
    public Response<Long> add(@Validated @RequestBody AttributeItemValueSaveDTO attributeItemValue) {
        return Response.success(attributeItemValueService.addAttributeItemValue(attributeItemValue));
    }

    @ApiOperation("修改属性项目值")
    @Log(businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public Response<Long> edit(@Validated @RequestBody AttributeItemValueUpdateDTO attributeItemValue) {
        return Response.success(attributeItemValueService.editAttributeItemValue(attributeItemValue));
    }

    @ApiOperation("删除属性项目值")
    @Log(businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "valueId", value = "属性项目值ID", required = true)
    })
    public Response<Void> remove(Long valueId) {
        attributeItemValueService.removeAttributeItemValue(valueId);
        return Response.success();
    }

    @ApiOperation("获取SKU属性和属性值组合信息列表")
    @GetMapping("/combineList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "categoryId", value = "分类ID", required = false)
    })
    public Response<List<AttributeItemCombineDTO>> getCombineList(@RequestParam(required = false) Long categoryId) {
        return Response.success(attributeItemValueService.selectAttributeItemCombineList(categoryId));
    }

//    @ApiOperation("根据属性项目ID获取属性值列表")
//    @GetMapping("/listByAttributeItemId")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "attributeItemId", value = "属性项目ID", required = true)
//    })
//    public Response<List<AttributeItemValueListDTO>> listByAttributeItemId(Long attributeItemId) {
//        return Response.success(attributeItemValueService.selectAttributeItemValueListByAttributeItemId(attributeItemId));
//    }
}
